package com.spark.market.api.utils;

import com.spark.market.api.enums.ResultEnum;

public class ResponseUtil {

    public static <T> ResponseResult<T> createSuccessResult(T data){
        ResponseResult<T> result = new ResponseResult<>();
        result.setData(data);
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        return result;
    }

    public static <T> ResponseResult<T> createSuccessResult(T data, String msg){
        ResponseResult<T> result = new ResponseResult<>();
        result.setData(data);
        result.setMsg(msg);
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        return result;
    }

    public static <T> ResponseResult<T> createFailedResult(String msg){
        ResponseResult<T> result = new ResponseResult<>();
        result.setMsg(ResultEnum.FAILED.getMsg());
        result.setCode(ResultEnum.FAILED.getCode());
        return result;
    }

    public static <T> ResponseResult<T> createFailedResult(T data, String msg){
        ResponseResult<T> result = new ResponseResult<>();
        result.setData(data);
        result.setMsg(ResultEnum.FAILED.getMsg());
        result.setCode(ResultEnum.FAILED.getCode());
        return result;
    }
}

